
/*-----------------------------------------------------------------------------\
|                          ChipCFlow Block2Code V1.0                           |
|                                                                              |
| Desenvolvedor: Felipe Simões Lage Gomes Duarte                               |
| Orientador: Prof. Dr. Jorge Luiz e Silva                                     |
| Supervisor: Bruno de Abreu Silva                                             |
|	      Joelmir José Lopes                                               |
|                                                                              |
| Main Project: ChipCflow                                                      |
| Período: Agosto de 2009 a Julho de 2010                                      |
| Codigo: Fonte.java                                                           |
| Versão da IDE: NetBeans IDE 6.8 (Build 200912041610)                         |
| Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13                          |
| Sistema Operacional: Windows 7 versão 6.1 executando em x86; pt_BR           |
|                                                                              |
|             O presente trabalho foi realizado com apoio do CNPq              |
|   Conselho Nacional de Desenvolvimento Científico  e Tecnológico - Brasil    |
\-----------------------------------------------------------------------------*/
package view;//Nome do pacote de dados.

//declaraçao das classes importadas
import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;

public class Fonte extends javax.swing.JFrame {

  private static Fonte SINGLETON;
  private String fonte; //Atributo com o Nome da Fonte
  private int tamanho; //Atributo com o Tamanho da Fonte
  private int estilo; //Atributo com o Estilo da Fonte
  protected Color cor; //Atributo com a cor da Fonte
  private Font fontFormat; //Variavel do tipo Font

  private Fonte() {
    initComponents();
    this.setLocation(((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (this.getWidth() / 2)),
            ((Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (this.getHeight() / 2)));
    //inicializa Font com valores Default
    this.fonte = "Courier New";
    this.estilo = Font.PLAIN;
    this.tamanho = 14;
    this.cor = new Color(0, 0, 0);

    this.estiloFonteLista.setSelectedIndex(0);
    this.tamanhoLista.setSelectedIndex(6);
    fontFormat = new Font(fonte, estilo, tamanho);

    fonteField.setText(fonte);
    estiloFonteField.setText((String) estiloFonteLista.getSelectedValue());
    tamanhoField.setText((String) tamanhoLista.getSelectedValue());

    VisualizarLabel.setText("ChipCFlow - Block2Code");

    //Pega as fontes disponiveis no sistema e preenche a lista com elas
    String[] fontNames; // nomes das fontes
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    fonteLista.setListData(fontNames);
  }

  public static Fonte getInstance() {
    if (SINGLETON == null) {
      SINGLETON = new Fonte();
    }
    return SINGLETON;
  }

  public Color getCor() {
    return cor;
  }

  public void setCor(Color cor) {
    this.cor = cor;
  }

  public int getEstilo() {
    return estilo;
  }

  public void setEstilo(int estilo) {
    this.estilo = estilo;
  }

  public String getFonte() {
    return fonte;
  }

  public void setFonte(String fonte) {
    this.fonte = fonte;
  }

  public int getTamanho() {
    return tamanho;
  }

  public void setTamanho(int tamanho) {
    this.tamanho = tamanho;
  }

  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    fonteLista = new javax.swing.JList();
    jScrollPane2 = new javax.swing.JScrollPane();
    estiloFonteLista = new javax.swing.JList();
    jScrollPane3 = new javax.swing.JScrollPane();
    tamanhoLista = new javax.swing.JList();
    fonteField = new javax.swing.JTextField();
    estiloFonteField = new javax.swing.JTextField();
    tamanhoField = new javax.swing.JTextField();
    fonteLabel = new javax.swing.JLabel();
    estiloFonteLabel = new javax.swing.JLabel();
    tamalhoLabel = new javax.swing.JLabel();
    jPanel1 = new javax.swing.JPanel();
    VisualizarLabel = new javax.swing.JLabel();
    cancelarButton = new javax.swing.JButton();
    aplicarButton = new javax.swing.JButton();
    okButton = new javax.swing.JButton();
    corButton = new javax.swing.JButton();

    setTitle("Formatar Fonte");
    setIconImage(new ImageIcon("src/Icones/progicon.png").getImage());

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    fonteLista.setName("fonteLista"); // NOI18N
    fonteLista.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        fonteListaValueChanged(evt);
      }
    });
    jScrollPane1.setViewportView(fonteLista);

    jScrollPane2.setName("jScrollPane2"); // NOI18N

    estiloFonteLista.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { "Plano ( Default )", "Negrito", "Italico" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    estiloFonteLista.setName("estiloFonteLista"); // NOI18N
    estiloFonteLista.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        estiloFonteListaValueChanged(evt);
      }
    });
    jScrollPane2.setViewportView(estiloFonteLista);

    jScrollPane3.setName("jScrollPane3"); // NOI18N

    tamanhoLista.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { "3", "5", "8", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36", "38", "40", "42", "44", "46", "48" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    tamanhoLista.setName("tamanhoLista"); // NOI18N
    tamanhoLista.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
      public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
        tamanhoListaValueChanged(evt);
      }
    });
    jScrollPane3.setViewportView(tamanhoLista);

    fonteField.setBackground(new java.awt.Color(204, 204, 204));
    fonteField.setEditable(false);
    fonteField.setName("fonteField"); // NOI18N

    estiloFonteField.setBackground(new java.awt.Color(204, 204, 204));
    estiloFonteField.setEditable(false);
    estiloFonteField.setName("estiloFonteField"); // NOI18N
    estiloFonteField.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        estiloFonteFieldActionPerformed(evt);
      }
    });

    tamanhoField.setName("tamanhoField"); // NOI18N
    tamanhoField.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        tamanhoFieldActionPerformed(evt);
      }
    });

    fonteLabel.setText("Fonte:");
    fonteLabel.setName("fonteLabel"); // NOI18N

    estiloFonteLabel.setText("Estilo de Fonte:");
    estiloFonteLabel.setName("estiloFonteLabel"); // NOI18N

    tamalhoLabel.setText("Tamanho:");
    tamalhoLabel.setName("tamalhoLabel"); // NOI18N

    jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Visualizar:"));
    jPanel1.setName("jPanel1"); // NOI18N

    VisualizarLabel.setName("VisualizarLabel"); // NOI18N

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(VisualizarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 401, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap())
    );
    jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
        .addComponent(VisualizarLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap())
    );

    cancelarButton.setText("Cancelar");
    cancelarButton.setName("cancelarButton"); // NOI18N
    cancelarButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cancelarButtonActionPerformed(evt);
      }
    });

    aplicarButton.setText("Aplicar");
    aplicarButton.setMaximumSize(new java.awt.Dimension(75, 23));
    aplicarButton.setMinimumSize(new java.awt.Dimension(75, 23));
    aplicarButton.setName("aplicarButton"); // NOI18N
    aplicarButton.setPreferredSize(new java.awt.Dimension(75, 23));
    aplicarButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        aplicarButtonActionPerformed(evt);
      }
    });

    okButton.setText("Ok");
    okButton.setMaximumSize(new java.awt.Dimension(75, 23));
    okButton.setMinimumSize(new java.awt.Dimension(75, 23));
    okButton.setName("okButton"); // NOI18N
    okButton.setPreferredSize(new java.awt.Dimension(75, 23));
    okButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        okButtonActionPerformed(evt);
      }
    });

    corButton.setText("Cor");
    corButton.setMaximumSize(new java.awt.Dimension(75, 23));
    corButton.setMinimumSize(new java.awt.Dimension(75, 23));
    corButton.setName("corButton"); // NOI18N
    corButton.setPreferredSize(new java.awt.Dimension(75, 23));
    corButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        corButtonActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 454, Short.MAX_VALUE)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addComponent(fonteLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(fonteField)
              .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addComponent(estiloFonteLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(estiloFonteField)
              .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(tamanhoField, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(tamalhoLabel))
            .addContainerGap())
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addComponent(corButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 133, Short.MAX_VALUE)
            .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(aplicarButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(cancelarButton)
            .addContainerGap())))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(19, 19, 19)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(estiloFonteLabel)
              .addComponent(tamalhoLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(estiloFonteField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(tamanhoField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addGroup(layout.createSequentialGroup()
            .addComponent(fonteLabel)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(fonteField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addGap(18, 18, 18)
        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(cancelarButton)
          .addComponent(aplicarButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(corButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
      this.setVisible(false);//fecha a janela Font
    }//GEN-LAST:event_okButtonActionPerformed

    private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
      this.setVisible(false);//fecha a janela Font
    }//GEN-LAST:event_cancelarButtonActionPerformed

    private void fonteListaValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_fonteListaValueChanged
      fonte = (String) this.fonteLista.getSelectedValue();
      fontFormat = new Font(fonte, estilo, tamanho);
      this.VisualizarLabel.setFont(fontFormat);
      this.fonteField.setText(fonte);
    }//GEN-LAST:event_fonteListaValueChanged

    private void tamanhoListaValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_tamanhoListaValueChanged
      tamanho = Integer.parseInt((String) this.tamanhoLista.getSelectedValue());
      fontFormat = new Font(fonte, estilo, tamanho);
      this.VisualizarLabel.setFont(fontFormat);
      this.tamanhoField.setText((String) this.tamanhoLista.getSelectedValue());
    }//GEN-LAST:event_tamanhoListaValueChanged

    private void estiloFonteListaValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_estiloFonteListaValueChanged

      String sEstilo = (String) this.estiloFonteLista.getSelectedValue();

      if (sEstilo.equals("Plano ( Default )")) {
        estilo = Font.PLAIN;
      } else if (sEstilo.equals("Negrito")) {
        estilo = Font.BOLD;
      } else if (sEstilo.equals("Italico")) {
        estilo = Font.ITALIC;
      }
      fontFormat = new Font(fonte, estilo, tamanho);
      this.VisualizarLabel.setFont(fontFormat);
      this.estiloFonteField.setText(sEstilo);
    }//GEN-LAST:event_estiloFonteListaValueChanged

    private void tamanhoFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tamanhoFieldActionPerformed
      tamanho = Integer.parseInt(tamanhoField.getText());
      fontFormat = new Font(fonte, estilo, tamanho);
      this.VisualizarLabel.setFont(fontFormat);
    }//GEN-LAST:event_tamanhoFieldActionPerformed

    private void aplicarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aplicarButtonActionPerformed
    }//GEN-LAST:event_aplicarButtonActionPerformed

    private void corButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_corButtonActionPerformed
      JColorChooser CorSelect = new javax.swing.JColorChooser();
      JOptionPane.showMessageDialog(this, CorSelect, "Seletor de Cores", JOptionPane.PLAIN_MESSAGE);
      cor = CorSelect.getColor();
      this.VisualizarLabel.setForeground(cor);
    }//GEN-LAST:event_corButtonActionPerformed

    private void estiloFonteFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estiloFonteFieldActionPerformed
      // TODO add your handling code here:
    }//GEN-LAST:event_estiloFonteFieldActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JLabel VisualizarLabel;
  private javax.swing.JButton aplicarButton;
  private javax.swing.JButton cancelarButton;
  private javax.swing.JButton corButton;
  private javax.swing.JTextField estiloFonteField;
  private javax.swing.JLabel estiloFonteLabel;
  private javax.swing.JList estiloFonteLista;
  private javax.swing.JTextField fonteField;
  private javax.swing.JLabel fonteLabel;
  private javax.swing.JList fonteLista;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JButton okButton;
  private javax.swing.JLabel tamalhoLabel;
  private javax.swing.JTextField tamanhoField;
  private javax.swing.JList tamanhoLista;
  // End of variables declaration//GEN-END:variables

  public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

      public void run() {
        new Fonte().setVisible(true);
      }
    });
  }
}
